#include <iostream>
#include <sys/epoll.h>
#include <errno.h>
#include <string.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <thread>
#include <chrono>
#include "EventLoop.h"
#include <sys/timerfd.h>
#include "timer.h"
#include <sigc++/trackable.h>
#include <sigc++/signal.h>
#include "../thread/thread_guard.h"
#include "../thread/scoped_thread.h"

class Mine: public sigc::trackable
{
public:
    Mine() 
    {
        m_sigc.connect(sigc::mem_fun(*this, &Mine::slot_haha));
    }

    void slot_haha()
    {
        std::cout << "haha slot" << std::endl;
    }

    sigc::signal<void()> m_sigc;
};

int main(int, char**) {
    std::cout << "Hello, world!\n";

    EventLoop loop;

    Mine m;
#if 0
    Timer::singleshot(5000, [&]() {
        std::cout << "haha" << std::endl;
        m.m_sigc();
        loop.quit();
    });
#endif

    std::thread t([&]() {
        std::this_thread::sleep_for(std::chrono::seconds(2));
        std::cout << "now will quit" << std::endl;
        m.m_sigc();
        loop.quit(); 
        });
    mystd::thread_guard tt(t);

    loop.loop();
}
